#include "Vector2.h"
#include "math/Math.h"

Vector2::Vector2()
	:x(0.0f), y(0.0f)
{
}

Vector2::Vector2(float x, float y)
	: x(x), y(y)
{
}

Vector2::Vector2(float value)
	: x(value), y(value)
{
}

const Vector2& Vector2::operator+=(const Vector2& right)
{
	x += right.x;
	y += right.y;
	return *this;
}

const Vector2& Vector2::operator-=(const Vector2& right)
{
	x -= right.x;
	y -= right.y;
	return *this;
}

const Vector2& Vector2::operator*=(const float& right)
{
	x *= right;
	y *= right;
	return *this;
}

float Vector2::SquareLength() const
{
	return x * x + y * y;
}

float Vector2::Length() const
{
	return Math::Sqrt(SquareLength());
}

Vector2 operator+(const Vector2& left, const Vector2& right)
{
	return Vector2(left.x + right.x, left.y + right.y);
}

Vector2 operator-(const Vector2& left, const Vector2& right)
{
	return Vector2(left.x - right.x, left.y - right.y);
}

Vector2 operator*(const float& value, const Vector2& right)
{
	return Vector2(right.x * value, right.y * value);
}

Vector2 operator*(const Vector2& left, const float& value)
{
	return value * left;
}

float operator*(const Vector2& left, const Vector2& right)
{
	return left.x * right.x + left.y * right.y;
}


Vector2 Vector2::Normalize(const Vector2& vec)
{
	Vector2 tmp = vec;
	float len = tmp.Length();
	tmp.x /= len;
	tmp.y /= len;
	return tmp;
}

float Vector2::Dot(const Vector2& left, const Vector2& right)
{
	return left * right;
}
